﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcAtletIS.Models
{
    [MetadataType(typeof(ClubsMetaData))]
    public partial class Clubs
    {
        public bool Checked { get; set; }
        
        public int CompetitorsCount 
        { 
            get 
            { 
                atletisEntities db = new atletisEntities();
                return db.Competitors.Where(c => c.Active == true & c.Competitor == true & c.ClubId == this.ID).Count();
            } 
        }

        public int CoachesCount
        {
            get
            {
                atletisEntities db = new atletisEntities();
                return db.Competitors.Where(c => c.Active == true & !string.IsNullOrEmpty(c.CoachClass) & c.ClubId == this.ID).Count();
            }
        }

        public int RefereesCount
        {
            get
            {
                atletisEntities db = new atletisEntities();
                return db.Competitors.Where(c => c.Active == true & !string.IsNullOrEmpty(c.RefereeClass) & c.ClubId == this.ID).Count();
            }
        }
    }

    public class ClubsMetaData
    {
        [Required(ErrorMessage = "ID je povinný údaj.")]
        public string ID { get; set; }

        [DisplayName("Názov")]
        [Required(ErrorMessage = "Názov je povinný údaj.")]
        public string Name { get; set; }

        [DisplayName("Mesto")]
        [Required(ErrorMessage = "Mesto je povinný údaj.")]
        public string City { get; set; }

        [DisplayName("Ulica")]
        public string Street { get; set; }

        [DisplayName("Telefón")]
        public string Phone { get; set; }

        [DisplayName("Email")]
        public string Email { get; set; }

        [DisplayName("Web")]
        public string Web { get; set; }

        [DisplayName("Aktívna")]
        [DefaultValue(true)]
        public bool Active { get; set; }

        [DisplayName("Synch.")]
        [DefaultValue(true)]
        public bool Sync { get; set; }
    }
}